package cn.edu.scnu.service;

import cn.edu.scnu.entity.Movie;
import cn.edu.scnu.mapper.GradeMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GradeService extends ServiceImpl<GradeMapper, Movie> {
    @Autowired
    private GradeMapper gradeMapper;
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    // 根据电影评分排序
    public List<Movie> sortMovieByScore() {
        QueryWrapper<Movie> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("score");
        return gradeMapper.selectList(queryWrapper);
    }

    // 根据周热度排序
    public List<Movie> sortMovieByWeekPopularity() {
        QueryWrapper<Movie> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("week_popularity");
        return gradeMapper.selectList(queryWrapper);
    }

    // 根据月热度排序
    public List<Movie> sortMovieByMonthPopularity() {
        QueryWrapper<Movie> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("month_popularity");
        return gradeMapper.selectList(queryWrapper);
    }
}
